from django.db import models
  
class Form(models.Model):
  name = models.CharField(max_length=50)
  code = models.CharField(max_length=5)
  
class Division(models.Model):
  code = models.CharField(max_length=1)
  name = models.CharField(max_length=20)
  
class AgeGroup(models.Model):
  code = models.CharField(max_length=1)
  name = models.CharField(max_length=20)
  
class Sex(models.Model):
  code = models.CharField(max_length=1)
  name = models.CharField(max_length=20)
  
class Event(models.Model):
  ring = models.IntegerField()
  order = models.IntegerField()
  form = models.ForeignKey(Form)
  division = models.ForeignKey(Division)
  age_group = models.ForeignKey(AgeGroup)
  sex = models.ForeignKey(Sex)
  code = models.CharField(max_length=6)
  completed = models.BooleanField()  # Is false if ongoing
  ongoing = models.BooleanField(default=False)    # Is false if completed
  start_time = models.DateTimeField(blank=True, null=True)
  end_time = models.DateTimeField(blank=True, null=True)
  num_competitors = models.IntegerField()
  def __str__(self):
    return '%d, %s' % (self.ring_id, self.code)
